package com.fengke.cn.yejian11.activity;

import android.app.Activity;
import android.os.Bundle;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.Toast;

import com.fengke.cn.yejian11.R;
import com.fengke.cn.yejian11.adapter.UserDingDanAdapter;
import com.fengke.cn.yejian11.base.BaseActivity;
import com.fengke.cn.yejian11.config.Config;
import com.fengke.cn.yejian11.impls.ActImpls;
import com.fengke.cn.yejian11.javabean.UserDingdan;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class UserDingDanActivity extends BaseActivity {

    private RecyclerView recyclerView;
    private Retrofit retrofit;
    private UserDingDanAdapter userDingDanAdapter;
    private List<UserDingdan> userDingden;
    private String User_Id;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_user_ding_dan);
        User_Id=getUserId();
//        User_Id="19";
//        String vstate="0";
        String page="1";
        String SessionID="pf2cmg5jk9p24f2mv1kjf55bo3";
        recyclerView= (RecyclerView) findViewById(R.id.user_dingdan_rec);
        Retrofit retrofit=new Retrofit.Builder().addConverterFactory(GsonConverterFactory.create()).baseUrl(Config.URL).build();
        ActImpls services=retrofit.create(ActImpls.class);
        retrofit2.Call<List<UserDingdan>> call=services.getUserDingDan(User_Id,page,SessionID);
        call.enqueue(new Callback<List<UserDingdan>>() {
            @Override
            public void onResponse(Call<List<UserDingdan>> call, Response<List<UserDingdan>> response) {
                List<UserDingdan> list=response.body();
                userDingDanAdapter=new UserDingDanAdapter(UserDingDanActivity.this,list);
                LinearLayoutManager linearLayoutManager=new LinearLayoutManager(UserDingDanActivity.this);
                linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
                recyclerView.setLayoutManager(linearLayoutManager);
                recyclerView.setAdapter(userDingDanAdapter);
                recyclerView.setItemAnimator(new DefaultItemAnimator());
            }

            @Override
            public void onFailure(Call<List<UserDingdan>> call, Throwable t) {

                Toast.makeText(UserDingDanActivity.this,"获取列表失败",Toast.LENGTH_LONG).show();

            }
        });
    }
}
